<template>
  <el-container class="home_container">
    <el-header>
      <div>
        <img src="../assets/sunpine.jpg" alt="" style="width: 50px;height: 50px;border-radius: 5px"/>
        <span>作品管理系统</span>
      </div>
      <el-button type="info" @click="logout">退出</el-button>
    </el-header>
    <el-container>
<!--      侧边栏-->
      <el-aside :width="isCollapse?'64px':'200px'">
        <div class="toggle-button" @click="toggleCollapse">|||</div>
<!--        菜单区-->
        <el-menu
          background-color="#333744"
          text-color="#fff"
          active-text-color="#409eff"
          :unique-opened="false"
          :collapse="isCollapse"
          :collapse-transition="false"
          :router="true"
          :default-active="activePath"
        >
          <el-submenu index="1">
            <template slot="title">
              <i class="el-icon-user-solid"></i>
              <span>用户系统</span>
            </template>
              <el-menu-item :index="'/'+'users'" @click="saveNavState('/'+'users')">
                <template slot="title">
                  <i class="el-icon-user-solid"></i>
                  <span>用户管理</span>
                </template>
              </el-menu-item>
              <el-menu-item :index="'/'+'roles'" @click="saveNavState('/'+'roles')">
                <template slot="title">
                  <i class="el-icon-fork-spoon"></i>
                  <span>角色管理</span>
                </template>
              </el-menu-item>
            <el-submenu :index="'/'+'privs'" @click="saveNavState('/'+'privs')">
              <template slot="title">
                <i class="el-icon-key"></i>
                <span>权限管理</span>
              </template>
              <el-menu-item index="1-3-1">
                <template slot="title">
                  <i class="el-icon-picture"></i>
                  <span>item three one</span>
                </template>
              </el-menu-item>
            </el-submenu>
          </el-submenu>
          <el-submenu index="2">
            <template slot="title">
              <i class="el-icon-picture"></i>
              <span>作品系统</span>
            </template>
            <el-menu-item :index="'/'+'works'" @click="saveNavState('/'+'works')">
              <template slot="title">
                <i class="el-icon-picture"></i>
                <span>作品管理</span>
              </template>
            </el-menu-item>
            <el-menu-item :index="'/'+'orders'" @click="saveNavState('/'+'orders')">
              <template slot="title">
                <i class="el-icon-goods"></i>
                <span>订单管理</span>
              </template>
            </el-menu-item>
          </el-submenu>
          <el-submenu index="3">
            <template slot="title">
              <i class="el-icon-picture"></i>
              <span>考勤系统</span>
            </template>
            <el-menu-item :index="'/'+'clockIn'" @click="saveNavState('/'+'clockIn')">
              <template slot="title">
                <i class="el-icon-user-solid"></i>
                <span>打卡管理</span>
              </template>
            </el-menu-item>
            <el-menu-item :index="'/'+'score'" @click="saveNavState('/'+'score')">
              <template slot="title">
                <i class="el-icon-location"></i>
                <span>成绩管理</span>
              </template>
            </el-menu-item>
            <el-menu-item :index="'/'+'askLeave'" @click="saveNavState('/'+'askLeave')">
              <template slot="title">
                <i class="el-icon-location"></i>
                <span>请假管理</span>
              </template>
            </el-menu-item>
          </el-submenu>
          <el-menu-item :index="'/'+'statis'" @click="saveNavState('/'+'statis')">
            <i class="el-icon-setting"></i>
            <span>数据统计</span>
          </el-menu-item>
        </el-menu>
      </el-aside>
<!--      主体区-->
      <el-main>
        <router-view></router-view>
      </el-main>
    </el-container>
    <el-footer>
      &copy;Sunpine工作室&nbsp;&nbsp;2021-2025
    </el-footer>
  </el-container>
</template>

<script>
    export default {
        data(){
          return {
              isCollapse:false,
              //定义图标对象
              iconObjs:{
                  '1':'el-icon-location',
                  '2':'el-icon-location',
                  '3':'el-icon-location',
                  '4':'el-icon-location'
              },
              //被激活的链接地址
              activePath:''
          }
        },
        name: "home",
        created(){
          this.getMenuList();
          this.activePath = window.sessionStorage.getItem('activePath');
        },
        methods: {
            //保存菜单状态
            saveNavState(activePath){
                window.sessionStorage.setItem("activePath",activePath);
                this.activePath = activePath;
            },
            toggleCollapse(){
              this.isCollapse = !this.isCollapse;
            },
            getMenuList(){
               this.$http({
                   url:'getMenuList',
                   method:'post'
               }).then(res=>{
                   console.log(res);
                   if (res.code !== 200) {
                       return this.$message.error({
                           showClose: true,
                           message: '菜单获取失败。'
                       });
                   }
                   this.menuList = res.data;
               }).catch(err=>{
                   return this.$message.error({
                       showClose: true,
                       message: '菜单获取失败。'
                   });
               })
           },
            logout() {
                window.sessionStorage.clear();
                this.$router.push('/login');
            }
        }
    }
</script>

<style lang="less" scoped>
  .home_container{
    height: 100%;
  }
  .el-header {
    background-color: #303133;

    line-height: 60px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: #fff;
    font-size: 20px;
    > div {
      display: flex;
      align-items: center;
      span{
        margin-left: 15px;
      }
    }
  }

  .el-aside{
    background-color: #333744;
    .el-menu{
      border-right: none;
    }
  }
  .el-main{
    background-color: #eaedf1;
  }
  .el-footer{
    background-color: #303133;
    color: #fff;
    line-height: 60px;
    display: flex;
    justify-content: center;
  }
  .toggle-button{
    background:#4A5064;
    font-size: 10px;
    line-height: 24px;
    color:#fff;
    text-align: center;
    letter-spacing: 0.2em;
    cursor: pointer;
  }
</style>